{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e0ade599",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy\n",
    "import pandas"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "013858f9",
   "metadata": {},
   "source": [
    "# pandas中的数学函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0c4180dc",
   "metadata": {},
   "source": [
    "- count() 非空值的数量\n",
    "- max() 最大值\n",
    "- min() 最小值\n",
    "- mediam() 中位数\n",
    "- sum() 求和\n",
    "- mean() 平均值\n",
    "---\n",
    "- value_counts() 统计元素出现的个数\n",
    "- cumsum() 累加\n",
    "- cumprod() 累乘\n",
    "- std() 标准差\n",
    "- var() 方差\n",
    "- cov() 协方差\n",
    "- corr() 所有属性相关性系数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4ecdd7ba",
   "metadata": {},
   "source": [
    "- 相关系数r\n",
    "    - 相关系数 = X与Y的协方差 / (X的标准差 * Y的标准差)\n",
    "    - 相关系数范围在-1到1之间\n",
    "    - r大于0为正相关，r小于0为负相关，r等于0表示不相关\n",
    "    - r的绝对值越大，相关程度越高"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a0ecabce",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pandas.DataFrame(data=numpy.random.randint(0,100,size=(3,3)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b1a0b6c2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0   -0.079172\n",
       "1   -0.963279\n",
       "2    1.000000\n",
       "dtype: float64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.corrwith(df[2]) # 单一特征相关系数"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
